package com.imooc.infra.mapping;

import com.imooc.business.domain.Collect;
import com.imooc.business.domain.Metadata;
import com.imooc.infra.repository.entity.TDataCenterCollect;
import com.imooc.infra.repository.entity.TDataCenterMetadata;
import com.imooc.module.collect.enums.SourceTypeEnum;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;

/**
 * @Author Tim
 * @Description:
 * @Version 1.0
 */
@Mapper(componentModel = "spring")
public interface MetadataMapping {

    @Mapping(source = "sourceType", target = "sourceType", qualifiedByName = "toSourceTypeStr")
    TDataCenterMetadata toEntity(Metadata metadata);

    @Mapping(source = "sourceType", target = "sourceType", qualifiedByName = "toSourceTypeEnum")
    Metadata toVo(TDataCenterMetadata metadata);

    @Named("toSourceTypeStr")
    default Integer toSourceTypeStr(SourceTypeEnum sourceTypeEnum){
        return sourceTypeEnum.getSourceValue();
    }

    @Named("toSourceTypeEnum")
    default SourceTypeEnum toSourceTypeEnum(Integer sourceType){
        return SourceTypeEnum.parse(sourceType);
    }
}
